package org.dromara.neutrinoproxy.client.mini;

import java.util.ArrayList;
import java.util.List;

public class ClientDataService {

    /**
     * 是否已连接
     */
    private boolean connected;

    /**
     * 是否连接中
     */
    private boolean connecting;

    /**
     * 当前的licenseKey
     */
    private String licenseKey;

    private List<IClientDataCallback> callbacks;

    public ClientDataService(){
        this.callbacks = new ArrayList<>();
    }

    /**
     * 添加回调
     * @param callback
     */
    public void addCallback(IClientDataCallback callback){
        this.callbacks.add(callback);
    }


    /**
     * 删除回调
     * @param callback
     */
    public void removeCallback(IClientDataCallback callback){
        this.callbacks.remove(callback);
    }


    /**
     * 触发数据变更
     */
    public void notifyDataChanged(){
        for(IClientDataCallback callback : callbacks){
            callback.onDataChanged(this);
        }
    }



    private static ClientDataService instance;
    public static ClientDataService getInstance(){
        if(instance == null){
            instance = new ClientDataService();
        }
        return instance;
    }

    public boolean isConnected() {
        return connected;
    }

    public void setConnected(boolean connected) {
        this.connected = connected;
    }

    public boolean isConnecting() {
        return connecting;
    }

    public void setConnecting(boolean connecting) {
        this.connecting = connecting;
    }

    public String getLicenseKey() {
        return licenseKey;
    }

    public void setLicenseKey(String licenseKey) {
        this.licenseKey = licenseKey;
    }
}
